package com.example.administrator.listener;

import android.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.myapp.MainActivity;
import com.example.administrator.myapp.R;
import com.example.administrator.until.MyTimer;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2016/11/19 0019.
 */

public class MyListener implements View.OnClickListener
{
    private MainActivity activity;

    private TimerTask sTimerTask;

    public void onClick(View view)
    {
        final TextView textView = (TextView) this.activity.findViewById(R.id.account);
        final TextView password = (TextView) this.activity.findViewById(R.id.pwd);

        AlertDialog.Builder builder = new AlertDialog.Builder(this.activity);
        if ("opjklu".equals( textView.getEditableText().toString()) && "123456".equals(password.getEditableText().toString()))
        {
            builder.setTitle("登陆成功");
            builder.setMessage("消息提示");
            builder.show();
            this.getHomeActivity(this.activity.getNextActivtiy(), this.activity, 2000);
        }
        else
        {
            builder.setTitle("登陆失败");
            builder.setMessage("消息提示");
            builder.show();
        }
    }

    public MainActivity newThis(MainActivity mainActivity)
    {
        return this.activity = mainActivity;
    }

    /**
     * 延时跳转
     */
    public void getHomeActivity(Class<? extends AppCompatActivity> nextActivity, AppCompatActivity thisActivity, int time)
    {

        Timer timer=new Timer();

        if (this.sTimerTask != null)
        {
            this.sTimerTask.cancel();
        }

        this.sTimerTask = MyTimer.getInition(nextActivity, thisActivity);

        timer.schedule(this.sTimerTask, time);
    }

}
